import React, { Suspense, lazy } from 'react';
import { Redirect } from "react-router-dom"
import BlankLayout from "../layout/BlankLayout"
const Main = lazy(() => import("../pages/main/Main"))
const My = lazy(() => import("../pages/my/My"))
const Shopping = lazy(() => import("../pages/shopping/Shopping"))
import Search from "../pages/search/Search"
import Detail from "../pages/detail/Detail"
import Tabbar from "../components/tabbar/Tabbar"

const SuspenseComponent = Component => props => {
    return (
        <Suspense fallback={null}>
            <Component {...props}></Component>
        </Suspense>
    )
}

export default [
    {
        component: BlankLayout,
        routes: [
            {
                path: '/',
                exact: true,
                render: () => < Redirect to={"/home"} />,
            },
            {
                path: '/detail',
                component: Detail,
                routes: [
                    {
                        path: ':id',
                        component: SuspenseComponent(Detail)
                    }
                ]
            },
            {
                path:'/search',
                component:Search,
                exact:true
            },
            {
                path: '/home',
                component: Tabbar,
                routes: [
                    {
                        path: '/home',
                        exact: true,
                        render: () => < Redirect to={"/home/main"}
                        />,
                    },
                    {
                        path: '/home/main',
                        component: SuspenseComponent(Main),
                    },
                    {
                        path: '/home/shopping',
                        component: SuspenseComponent(Shopping),
                    },
                    {
                        path: '/home/my',
                        component: SuspenseComponent(My),
                    },

                ]
            },
           
        ]
    },
    
]

